package my2Cents.tools;

import java.awt.event.MouseEvent;

import my2Cents.Bomb;
import my2Cents.Sandbox;
import my2Cents.properties.CheckBox;
import my2Cents.properties.Property;
import my2Cents.properties.Slider;
import net.phys2d.math.Vector2f;
import net.phys2d.raw.Body;
import net.phys2d.raw.shapes.PCircle;

public class BombTool extends AbstractBodyMaker {
	private float size = 8;
	private int timer = 0;
	private int power = 100;
	private boolean makeFragments;
	
	public BombTool() {
		setName("Bomb");
		setDescription(
				"Click to create a Bomb.\n" +
				"Adjust delay using the slider below."
			);
		Property p = new Slider("Timer",0,0,30,10,true) {
			public void valueChanged(int value) {
				timer = value;
			}
		};
		this.addProperty(p);
		
		Property p2 = new Slider("Power",0,0,200,50,true) {
			public void valueChanged(int value) {
				power = value;
			}			
		};
		this.addProperty(p2);
		
		Property p3 = new Slider("Size",0,8,80,20,true) {
			public void valueChanged(int value) {
				size = value;
			}			
		};
		this.addProperty(p3);
		
		CheckBox check = new CheckBox("Create Fragments",false) {
			private static final long serialVersionUID = 1L;

			public void valueChanged(boolean b) {
				makeFragments = b;
			}
		};
		addProperty(check);
	}
	
	public void startTool(MouseEvent arg0) {
		super.startTool(arg0);
		shapePos = new Vector2f(arg0.getX(), arg0.getY());
		shape = new PCircle(size);
		Body b = new Bomb(shape, size*2, timer, getWorld().getBodies(), Sandbox.makeStatic);
		b.setMoveable(!createStatic);
		b.setPosition(arg0.getX(), arg0.getY());
		b.setRotation(0);
		Bomb bombEnt = (Bomb) b;
		bombEnt.setPower(power);
		bombEnt.makeFragments(makeFragments);
		sandbox.postBodyCreated(b);
		endTool(arg0);
	}
}
